<!--test.vue-->
<template>
  <div class="tab-list" style="width: 100%; height: 100%">
    <ul class="list">
      <li
        v-for="(item, index) in area"
        class="list-item"
        :key="index"
        @click="select(index)"
        :class="[index === nowIndex ? 'active' : '']"
      >
        <img class="img" src="./1@2x.png" />
        {{ item.name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "tabList", // 这个名字很重要，它就是未来的标签名
  //   props: {
  //     text: {
  //       type: String,
  //       default: "这是一段文字"
  //     }
  //   },
  data() {
    return {
      nowIndex: 0,
      area: [
        {
          name: "某山一号小区"
        },
        {
          name: "某山二号小区"
        },
        {
          name: "某山三号小区"
        },
        {
          name: "某山四号小区"
        },
        {
          name: "某山五号小区"
        },
        {
          name: "某山六号小区"
        },
        {
          name: "某山七号小区"
        },
        {
          name: "某山八号小区"
        },
        {
          name: "某山九号小区"
        },
        {
          name: "某山十号小区"
        },
        {
          name: "某山一号小区"
        },
        {
          name: "某山二号小区"
        },
        {
          name: "某山三号小区"
        },
        {
          name: "某山四号小区"
        },
        {
          name: "某山五号小区"
        },
        {
          name: "某山六号小区"
        },
        {
          name: "某山七号小区"
        },
        {
          name: "某山八号小区"
        },
        {
          name: "某山九号小区"
        },
        {
          name: "某山十号小区"
        }
      ]
    };
  },
  methods: {
    select(index) {
      this.nowIndex = index;
    }
  },
  mounted() {
    let MutationObserver =
      window.MutationObserver ||
      window.WebKitMutationObserver ||
      window.MozMutationObserver;
    let element = document.getElementById("scrollBoard");
    this.observer = new MutationObserver(mutationList => {
      for (let mutation of mutationList) {
        console.log(mutation);
      }
      console.log("自适应");
      this.key++;
      //this.$forceUpdate()
      console.log('this.$refs["scrollBoard"]', this.$refs["scrollBoard"]);
    });
    this.observer.observe(element, {
      attributes: true,
      attributeFilter: ["style"],
      attributeOldValue: true
    });
  }
};
</script>

<style lang="scss" scoped>
.tab-list {
  width: 100%;
  height: 100%;
  .list {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;

    .list-item {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      flex: 1;
      margin-top: -1px;
      cursor: pointer;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      vertical-align: middle;
      min-width: 140px;
      height: 31px;
      border-radius: 0px;
      background: #23262c;
      font-family: SourceHanSansCN-Normal;
      font-size: 10px;
      color: #eeeeee;
      letter-spacing: 0;
      text-align: center;
      font-weight: 400;
      &:hover {
        background-color: rgba(36, 38, 46, 0.8);
      }
      .img {
        width: 10px;
        height: 10px;
        margin-right: 5px;
      }
    }
    .active {
      background-color: #3779fd;
    }
  }
}
</style>
